package besteAukera;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Vector;

public class Dekodegailu extends Konbinazionalak {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea = new Vector<Hanka>();
	private Vector<Hanka> sarreraBektorea = new Vector<Hanka>();
	private Hanka s1, s2, i3, i4, i1, i2, s3, s4, i5, i6, i7, i8;

	public Dekodegailu(int x1, int y1, int hankaKop, int sarreraKopMax,
			String mota, Color kolorea) {
		super(x1, y1, hankaKop, sarreraKopMax, mota, kolorea);
		// TODO Auto-generated constructor stub
		if (this.mota.compareTo("bi")==0) {
			s1 = new Hanka(x - 20, y + 20, "positiboa", "s", 0, this, "h", "ez",true);
			s2 = new Hanka(x - 20, y + 40, "positiboa", "s", 1, this, "h", "ez",true);
			s3 = new Hanka(x + 20, y - 20, "negatiboa", "s", 2, this, "b", "ez",true);
			i1 = new Hanka(x + 60, y, "positiboa", "i", 3, this, "h", "ez",true);
			i2 = new Hanka(x + 60, y + 20, "positiboa", "i", 4, this, "h", "ez",true);
			i3 = new Hanka(x + 60, y + 40, "positiboa", "i", 5, this, "h", "ez",true);
			i4 = new Hanka(x + 60, y + 60, "positiboa", "i", 6, this, "h", "ez",true);
		
			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = i1;
			lotList[4] = i2;
			lotList[5] = i3;
			lotList[6] = i4;
			
		}
		if (this.mota.compareTo("hiru")==0) {
			s1 = new Hanka(x - 20, y + 15, "positiboa", "s", 0, this, "h", "ez",true);
			s2 = new Hanka(x - 20, y + 35, "positiboa", "s", 1, this, "h", "ez",true);
			s3 = new Hanka(x - 20, y + 55, "positiboa", "s", 2, this, "h", "ez",true);
			s4 = new Hanka(x + 25, y - 25, "negatiboa", "s", 3, this, "b", "ez",true);
			 i1 = new Hanka(x + 70, y -15, "positiboa", "i", 4, this, "h","ez",true);
			 i2 = new Hanka(x + 70, y , "positiboa", "i", 5, this, "h","ez",true);
			 i3 = new Hanka(x + 70, y + 15, "positiboa", "i", 6, this, "h","ez",true);
			 i4 = new Hanka(x + 70, y + 30, "positiboa", "i", 7, this, "h", "ez",true);
			 i5 = new Hanka(x + 70, y + 45, "positiboa", "i", 8, this, "h", "ez",true);
			 i6 = new Hanka(x + 70, y + 60, "positiboa", "i", 9, this, "h","ez",true);
			 i7 = new Hanka(x + 70, y + 75, "positiboa", "i", 10, this, "h","ez",true);
			 i8 = new Hanka(x + 70, y + 90, "positiboa", "i", 11, this, "h","ez",true);

			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			 lotList[4] = i1;
			 lotList[5] = i2;
			 lotList[6] = i3;
			 lotList[7] = i4;
			 lotList[8] = i5;
			 lotList[9] = i6;
			 lotList[10] = i7;
			 lotList[11] = i8;

		}
	}

	public void marraztu(Graphics g) {

		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		
		g.setColor(kolorea);
		if (this.mota.compareTo("bi")==0) {
		
			// goikoa
			g.drawLine(x, y + 10, x + 40, y - 10);
			// beikoa
			g.drawLine(x, y + 50, x + 40, y + 70);
			// ezkerretakoa
			g.drawLine(x, y + 10, x, y + 50);
			// eskubitakoa
			g.drawLine(x + 40, y - 10, x + 40, y + 70);
		
//			g.setColor(Color.black);
			Font lehenetsia=g.getFont();
			Font f=new Font("name",Font.BOLD,9);
			g.setFont(f);
			g.drawString("0", x+2, y+25);
			g.drawString("1", x+2 , y + 45);
			g.drawString("0", x + 33, y + 5);
			g.drawString("1", x + 33, y + 25);
			g.drawString("2", x + 33, y + 45);
			g.drawString("3", x + 33, y + 65);
		g.setFont(lehenetsia);
			g.setColor(kolorea);
			s1.marraztu(g);
			s2.marraztu(g);
			s3.marraztu(g);
			i1.marraztu(g);
			i2.marraztu(g);
			i3.marraztu(g);
			i4.marraztu(g);
			
		}
		if (this.mota.compareTo("hiru")==0) {
		
			// goikoa
			g.drawLine(x, y + 10, x + 50, y - 24);
			// beikoa
			g.drawLine(x, y + 65, x + 50, y +99);
			// ezkerretakoa
			g.drawLine(x, y + 10, x, y + 65);
			// eskubitakoa
			g.drawLine(x + 50, y - 24, x + 50, y + 99);
			g.setColor(Color.black);
			Font lehenetsia=g.getFont();
			Font f=new Font("name",Font.BOLD,9);
			g.setFont(f);
			g.drawString("0", x+2, y+20);
			g.drawString("1", x+2 , y + 40);
			g.drawString("2", x+2 , y + 60);
			g.drawString("0", x + 44, y -10);
			g.drawString("1", x + 44, y + 5);
			g.drawString("2", x + 44, y + 20);
			g.drawString("3", x + 44, y + 35);
			g.drawString("4", x + 44, y + 50);
			g.drawString("5", x + 44, y + 65);
			g.drawString("6", x + 44, y + 80);
			g.drawString("7", x + 44, y + 95);
		g.setFont(lehenetsia);
			g.setColor(kolorea);
			s1.marraztu(g);
			s2.marraztu(g);
			s3.marraztu(g);
			s4.marraztu(g);
			 i1.marraztu(g);
			 i2.marraztu(g);
			 i3.marraztu(g);
			 i4.marraztu(g);
			 i5.marraztu(g);
			 i6.marraztu(g);
			 i7.marraztu(g);
			 i8.marraztu(g);
					
		}
	}

	public boolean barruanDago(int x, int y) {
		if ((x > this.x) && (x < (this.x + 40)) && (y > this.y)
				&& (y < (this.y + 70))) {
			return true;
		}
		return false;

	}

	@Override
	public void funtzioLogikoa(Integer... values) {
		// TODO Auto-generated method stub
	if (mota.compareTo("bi")==0){
		lotList[3].getIrteera().setBalioa(s3.getSarrera().getBalioa() & ~(s1.getSarrera().getBalioa())& ~(s2.getSarrera().getBalioa()));
		lotList[4].getIrteera().setBalioa(s3.getSarrera().getBalioa() & s1.getSarrera().getBalioa()& ~(s2.getSarrera().getBalioa()));
		lotList[5].getIrteera().setBalioa(s3.getSarrera().getBalioa() & ~(s1.getSarrera().getBalioa())& s2.getSarrera().getBalioa());
		lotList[6].getIrteera().setBalioa(s3.getSarrera().getBalioa() & s1.getSarrera().getBalioa()& s2.getSarrera().getBalioa());
	}
	else if(mota.compareTo("hiru")==0){
		lotList[4].getIrteera().setBalioa(s4.getSarrera().getBalioa()&~(s3.getSarrera().getBalioa())&~(s2.getSarrera().getBalioa())&~(s1.getSarrera().getBalioa()));
		 lotList[5].getIrteera().setBalioa(s4.getSarrera().getBalioa()&~(s3.getSarrera().getBalioa())&~(s2.getSarrera().getBalioa())&(s1.getSarrera().getBalioa()));
		 lotList[6].getIrteera().setBalioa(s4.getSarrera().getBalioa()&~(s3.getSarrera().getBalioa())&(s2.getSarrera().getBalioa())&~(s1.getSarrera().getBalioa()));
		 lotList[7].getIrteera().setBalioa(s4.getSarrera().getBalioa()&~(s3.getSarrera().getBalioa())&(s2.getSarrera().getBalioa())&(s1.getSarrera().getBalioa()));
		 lotList[8].getIrteera().setBalioa(s4.getSarrera().getBalioa()&(s3.getSarrera().getBalioa())&~(s2.getSarrera().getBalioa())&~(s1.getSarrera().getBalioa()));
		 lotList[9].getIrteera().setBalioa(s4.getSarrera().getBalioa()&(s3.getSarrera().getBalioa())&~(s2.getSarrera().getBalioa())&(s1.getSarrera().getBalioa()));
		 lotList[10].getIrteera().setBalioa(s4.getSarrera().getBalioa()&(s3.getSarrera().getBalioa())&(s2.getSarrera().getBalioa())&~(s1.getSarrera().getBalioa()));
		 lotList[11].getIrteera().setBalioa(s4.getSarrera().getBalioa()&(s3.getSarrera().getBalioa())&(s2.getSarrera().getBalioa())&(s1.getSarrera().getBalioa()));
	}		
	}

	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub
		hankaBektorea = new Vector<Hanka>();
		if (this.mota.compareTo("bi")==0) {

			hankaBektorea.addElement(s1);
			hankaBektorea.addElement(s2);
			hankaBektorea.addElement(s3);
			hankaBektorea.addElement(i1);
			hankaBektorea.addElement(i2);
			hankaBektorea.addElement(i3);
			hankaBektorea.addElement(i4);
		}
		if (this.mota.compareTo("hiru")==0) {
			hankaBektorea.addElement(s1);
			hankaBektorea.addElement(s2);
			hankaBektorea.addElement(s3);
			hankaBektorea.addElement(s4);
			hankaBektorea.addElement(i1);
			hankaBektorea.addElement(i2);
			hankaBektorea.addElement(i3);
			hankaBektorea.addElement(i4);
			hankaBektorea.addElement(i5);
			hankaBektorea.addElement(i6);
			hankaBektorea.addElement(i7);
			hankaBektorea.addElement(i8);

		}
		return hankaBektorea;
	}

	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub
		sarreraBektorea = new Vector<Hanka>();
		if (this.mota.compareTo("bi")==0) {
			sarreraBektorea.addElement(s1);
			sarreraBektorea.addElement(s2);
			sarreraBektorea.addElement(s3);
		}
		if (this.mota.compareTo("hiru")==0) {
			hankaBektorea.addElement(s1);
			hankaBektorea.addElement(s2);
			hankaBektorea.addElement(s3);
			hankaBektorea.addElement(s4);
		}
		return sarreraBektorea;
	}

}
